package com.siwei.mes.entity.system;

import cn.dev33.satoken.stp.StpUtil;
import com.siwei.mes.common.validator.UpdateGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;


/**
 * 系统设置(SystemConfig)实体类
 *
 * @author linzi
 * @since 2024-05-23 21:18:14
 */
@Data
@Accessors(chain = true)
@Table(name = "pk_system_config")
@ApiModel(value = "SystemConfig", description = "系统设置")
public class SystemConfig implements Serializable {
    private static final long serialVersionUID = -59747610872724918L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "系统设置主键ID", name = "id")
    @NotNull(groups = {UpdateGroup.class}, message = "系统设置主键id为空")
    private Long id;
    /**
     * 1-标准模式 2-简洁模式
     */
    @Column(name = "system_model")
    @ApiModelProperty(value = "1-标准模式 2-简洁模式", name = "systemModel")
    @NotNull(groups = {UpdateGroup.class}, message = "模式类型为空")
    private Long systemModel;
    /**
     * 创建人
     */
    @Column(name = "creater")
    @ApiModelProperty(value = "创建人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */
    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    public SystemConfig init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date())
                    .setIsDel(0);
        }
        return this;
    }
}
